﻿
Imports IDServer
Imports System
Imports System.IO
Imports System.String
Imports System.Data

Public Class Frm_SYSUser

    Implements IDServer.IDServer.IDServer


    Private ActionHelp As IDServer.IDServer.ActionBtn = IDServer.IDServer.ActionBtn.ActionHelp
    Public mDataset As DataSet
    Private SelectNode As TreeNode
    Private Img As ImageList
    Public bFind As Boolean
    Private WithEvents MainForm As Frm_MainForm

    Public Property SelectObject() As Frm_MainForm
        Get
            Return MainForm
        End Get
        Set(ByVal value As Frm_MainForm)
            MainForm = value
        End Set
    End Property


#Region "SelfDefine sub or function"


    Private Sub Frm_SYSUser_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            LoadTree(Me.TreeView1)
            LoadPurviewGroup()
            LoadUserName()
            ClearText()
            SetCtlEnable(False)
            Me.CheckBox2.Enabled = False
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub LoadTree(ByVal Tv As TreeView)
        Try
            Dim mNode As New TreeNode
            Img = New ImageList()
            Dim Company As String = Application.StartupPath & "\pic\35FLOPPY.BMP"
            Dim bumen As String = Application.StartupPath & "\pic\CLSDFOLD.BMP"
            Dim gangwei As String = Application.StartupPath & "\pic\OPENFOLD.BMP"
            Dim Image As Image = Nothing
            Img.Images.Add(Drawing.Image.FromFile(Company))
            Img.Images.Add(Drawing.Image.FromFile(bumen))
            Img.Images.Add(Drawing.Image.FromFile(gangwei))
            Tv.ImageList = Img
            mNode.Nodes.Clear()
            mNode.Tag = "All"
            mNode.Text = "全部"
            Tv.ImageIndex = 0
            Tv.Nodes.Add(mNode)
            SelectNode = mNode
            LoadSecondTree(mNode)
            Tv.SelectedNode = SelectNode
            SelectNode.Expand()
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub LoadSecondTree(ByVal Nodes As TreeNode)
        Try
            Dim sql As String = ""
            sql = "select a.ID,a.UserCode,a.UserName,a.Password,a.StartDate,a.EndDate,a.Remark,b.GroupCode,b.GroupName from dbo.Sys_UserManage a inner join Sys_Group b on a.GroupId=b.GroupCode where a.Status=0 and b.GroupStatus=0"
            mDataset = New DataSet
            mDataset = ReturnDataset(sql)
            If Not mDataset Is Nothing Then
                For Each mRow As DataRow In mDataset.Tables(0).Rows
                    Dim Node1 As New TreeNode
                    Node1.Tag = mRow("ID")
                    Node1.Text = "(" & mRow("UserCode") & ")" & mRow("UserName") & ""
                    Node1.ImageIndex = 1
                    Node1.SelectedImageIndex = 2
                    Nodes.Nodes.Add(Node1)
                Next
            End If
        Catch ex As Exception
            MsgBox("LoadSecondTree:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    Private Sub LoadPurviewGroup()
        Try
            Dim sql As String = ""
            Dim m_ds As New DataSet

            sql = "select GroupCode,GroupName from dbo.Sys_Group"
            m_ds = ReturnDataset(sql)
            Me.ComboBox1.DisplayMember = "GroupName"
            Me.ComboBox1.ValueMember = "GroupCode"
            Me.ComboBox1.DataSource = m_ds.Tables(0)
            Me.ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
        Catch ex As Exception
            MsgBox("LoadPurviewGroup:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    Private Sub LoadUserName()

        Try
            Dim sql As String = ""
            Dim UserDS As New DataSet
            sql = "select * from dbo.BSC_Employee where fStatus=0"
            UserDS = ReturnDataset(sql)

            Me.cmbUserCode.DisplayMember = "fCode"
            Me.cmbUserCode.ValueMember = "fCName"
            Me.cmbUserCode.DataSource = UserDS.Tables(0)
            Me.cmbUserCode1.DisplayMember = "fCode"
            Me.cmbUserCode1.ValueMember = "fCName"
            Me.cmbUserCode1.DataSource = UserDS.Tables(0).Copy
            'Me.cmbUserCode.DropDownStyle = ComboBoxStyle.DropDownList
        Catch ex As Exception
            MsgBox("LoadUserName-->>" + ex.ToString, MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try

    End Sub

    Private Sub SetCtlEnable(ByVal B As Boolean)
        Me.txtUserName.Enabled = False
        If ActionHelp = IDServer.IDServer.ActionBtn.ActionEdit Then
            Me.txtParssward.Enabled = B And Me.CheckBox2.Checked = True
            Me.txtRePassword.Enabled = B And Me.CheckBox2.Checked = True
        Else
            Me.txtParssward.Enabled = B
            Me.txtRePassword.Enabled = B
        End If
        Me.txtStartDate.Enabled = B
        Me.cmbUserCode.Enabled = B
        Me.txtEndDate.Enabled = B
        Me.CheckBox1.Enabled = B
        Me.TreeView1.Enabled = Not B
        Me.BtnOK.Enabled = B
        Me.BtnCancel.Enabled = B
        Me.ComboBox1.Enabled = B
    End Sub

    Private Function BtnActionSave() As Boolean
        Try
            Dim sql As String = ""
            Dim ID As Integer
            Dim ds As New DataSet
            Dim mEncrypt As New IDServer.IDSecurity
            Dim txtUserCode As String = Me.cmbUserCode.Text.Replace("'", "")
            Dim txtUserName As String = Me.txtUserName.Text.Replace("'", "")
            Dim txtPassword As String = mEncrypt.DataEncrypt(Me.txtParssward.Text.Replace("'", ""))
            Dim txtStartDate As String = Me.txtStartDate.Text
            Dim txtEndDate As String = Me.txtEndDate.Text
            Dim GroupID As String = Me.ComboBox1.SelectedValue.ToString
            Dim IsForBid As Integer = IIf(Me.CheckBox1.Checked = True, 1, 0)

            If ActionInitialize() = False Then Exit Function

            If ActionHelp = IDServer.IDServer.ActionBtn.ActionAdd Then
                sql = "Insert Into Sys_UserManage(UserCode,UserName,Password,GroupID,StartDate,EndDate,Status,BuildPerson,BuildComputer) values('" & txtUserCode & "','" & txtUserName & "','" & txtPassword & "','" & GroupID & "','" & _
                            txtStartDate & "','" & txtEndDate & "'," & IsForBid & ",'" & PubUserName & "','" & My.Computer.Name & "');"

                sql += "select @@IDENTITY as ID"

                ds = ReturnDataset(sql)

                ID = ds.Tables(0).Rows(0).Item("ID")

                sql = "Insert Into Sys_LoginInfo(LoginID,LoginStatus) values('" & ID & "',0)"
                ReturnObject(sql)
                AddToDataSet(ID, txtUserCode, txtUserName, txtPassword, GroupID, txtStartDate, txtEndDate, IsForBid)
                AddtoTreeView(Me.TreeView1.Nodes(0), "(" & txtUserCode & ")" & txtUserName, ID)
            ElseIf ActionHelp = IDServer.IDServer.ActionBtn.ActionEdit Then
                If Me.CheckBox2.Checked = True Then
                    sql = "Update Sys_UserManage set UserCode='" & txtUserCode & "',UserName='" & txtUserName & "',Password='" & txtPassword & "',GroupID='" & GroupID & "',StartDate='" & txtStartDate & "',EndDate='" & txtEndDate & "',Status=" & IsForBid & ",UpdateDate=getdate(),UpdatePerson='" & PubUserName & "',UpdateComputer='" & My.Computer.Name & "' where ID=" & Me.TreeView1.SelectedNode.Tag
                Else
                    sql = "Update Sys_UserManage Set UserCode='" & txtUserCode & "',UserName='" & txtUserName & "',GroupID='" & GroupID & "',StartDate='" & txtStartDate & "',EndDate='" & txtEndDate & "',Status=" & IsForBid & ",UpdateDate=getdate(),UpdatePerson='" & PubUserName & "',UpdateComputer='" & My.Computer.Name & "' where ID=" & Me.TreeView1.SelectedNode.Tag
                End If
                ReturnObject(sql)
                EditToDataSet(txtUserCode, txtUserName, txtPassword, GroupID, txtStartDate, txtEndDate, IsForBid)
                Me.TreeView1.SelectedNode.Text = txtUserCode
            End If

            MsgBox(IIf(ActionHelp = IDServer.IDServer.ActionBtn.ActionAdd, My.Resources.AddSuccess, My.Resources.EditSuccess), MsgBoxStyle.Information + MsgBoxStyle.OkOnly, Msg.CompanyName)
            ActionHelp = IDServer.IDServer.ActionBtn.ActionHelp
            Me.CheckBox2.Enabled = False
            SetCtlEnable(False)
            Me.TreeView1.Enabled = True
            bFind = True
            MainForm.BtnEnable(bFind)
            GetToolEnable()
            Return True
        Catch ex As Exception
            MsgBox("BtnActionSave:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Function

    Private Sub AddToDataSet(ByVal ID As String, ByVal UserCode As String, ByVal UserName As String, ByVal Password As String, ByVal GroupID As String, ByVal StratDate As String, ByVal EndDate As String, ByVal Isforbid As Integer)
        Try
            If mDataset Is Nothing Then Exit Sub
            Dim mRow As DataRow = mDataset.Tables(0).NewRow
            mRow("ID") = ID
            mRow("UserCode") = UserCode
            mRow("UserName") = UserName
            mRow("Password") = Password
            'mRow("GroupID") = GroupID
            mRow("StartDate") = StratDate
            mRow("EndDate") = EndDate
            'mRow("Status") = Isforbid
            mDataset.Tables(0).Rows.Add(mRow)
            mDataset.AcceptChanges()
        Catch ex As Exception
            MsgBox("AddToDataSet:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    Private Sub EditToDataSet(ByVal UserCode As String, ByVal UserName As String, ByVal Password As String, ByVal GroupId As String, ByVal StratDate As String, ByVal EndDate As String, ByVal Isforbid As Integer)
        Try
            Dim Rows() As DataRow = mDataset.Tables(0).Select("ID=" & Me.TreeView1.SelectedNode.Tag)
            If Rows.Length > 0 Then
                For Each mRow As DataRow In Rows
                    mRow("UserCode") = UserCode
                    mRow("UserName") = UserName
                    mRow("Password") = Password
                    'mRow("GroupID") = GroupId
                    mRow("StartDate") = StratDate
                    mRow("EndDate") = EndDate
                    'mRow("Status") = Isforbid
                Next
            End If
            mDataset.AcceptChanges()
        Catch ex As Exception
            MsgBox("EditToDataSet:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    Private Sub AddtoTreeView(ByVal Nodes As TreeNode, ByVal UserName As String, ByVal ID As Integer)
        Try
            Dim Node1 As New TreeNode
            Node1.Tag = ID
            Node1.Text = UserName
            Node1.ImageIndex = 1
            Node1.SelectedImageIndex = 2
            Nodes.Nodes.Add(Node1)
            Node1.TreeView.SelectedNode = Node1
        Catch ex As Exception
            MsgBox("AddtoTreeView:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    Private Function DeleteFromDataSet(ByVal ID As String) As Boolean
        Dim sql As String
        Try
            sql = "Delete Sys_UserManage where id=" & ID
            ReturnObject(sql)
            Me.TreeView1.SelectedNode.Remove()
            Return True

        Catch ex As Exception
            MsgBox("DeleteFromDataSet:" + ex.ToString, MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Function

    Private Sub FillText(ByVal ID As Integer)
        Try
            Dim Rows() As DataRow = mDataset.Tables(0).Select("ID=" & ID)
            If Rows.Length > 0 Then
                For Each mRow As DataRow In Rows
                    Me.cmbUserCode.Text = mRow("UserCode") & ""
                    Me.txtUserName.Text = mRow("UserName") & ""
                    Me.txtParssward.Text = mRow("Password") & ""
                    Me.txtRePassword.Text = mRow("Password") & ""
                    Me.ComboBox1.Text = mRow("GroupName") & ""
                    Me.txtStartDate.Text = mRow("StartDate") & ""
                    Me.txtEndDate.Text = mRow("EndDate") & ""
                Next
            End If
        Catch ex As Exception
            MsgBox("FillText:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    Private Sub clearText()
        Me.cmbUserCode.Text = ""
        Me.txtUserName.Text = ""
        Me.txtParssward.Text = ""
        Me.txtRePassword.Text = ""
        Me.ComboBox1.SelectedIndex = -1
        Me.txtStartDate.Text = ""
        Me.txtEndDate.Text = ""
    End Sub

    Private Sub GetToolEnable()
        Try
            With MainForm
                .ToolStripAdd.Enabled = AddEnable
                .ToolStripEdit.Enabled = EditEnable
                .ToolStripDelete.Enabled = DeleteEnable
                .ToolStripPrint.Enabled = PrintEnable
                .ToolStripImport.Enabled = ImportEnable
                .ToolStripExport.Enabled = ExportEnable
                .ToolStripFind.Enabled = FindEnable
                .ToolStripCheck.Enabled = CheckEnable
                .ToolStripUnCheck.Enabled = UncheckEnable
                .ToolStripComplete.Enabled = CompleteEnable
                .AddToolStripMenuItem.Enabled = .ToolStripAdd.Enabled
                .Edit1ToolStripMenuItem.Enabled = .ToolStripEdit.Enabled
                .DelToolStripMenuItem.Enabled = .ToolStripDelete.Enabled
                .SaveToolStripMenuItem.Enabled = .ToolStripSave.Enabled
                .CancelToolStripMenuItem.Enabled = .ToolStripCancel.Enabled
                .PrintToolStripMenuItem.Enabled = .ToolStripPrint.Enabled
                .ExportToolStripMenuItem.Enabled = .ToolStripImport.Enabled
                .ImportToolStripMenuItem.Enabled = .ToolStripExport.Enabled
                .FilterToolStripMenuItem.Enabled = .ToolStripFilter.Enabled
            End With

        Catch ex As Exception
            MsgBox("GetToolEnable:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

#End Region

#Region "Interface Define"



    Public Function ActionAdd() As Boolean Implements IDServer.IDServer.IDServer.ActionAdd
        If AddEnable = False Then
            MessageBox.Show(My.Resources.NotAllowAdd, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Function
        End If

        ActionHelp = IDServer.IDServer.ActionBtn.ActionAdd
        clearText()
        MainForm.BtnEnable(False)
        SetCtlEnable(True)
        Me.TreeView1.Enabled = False
        Me.CheckBox2.Enabled = False
        Me.txtUserName.Focus()
    End Function

    Public Function ActionCancel() As Boolean Implements IDServer.IDServer.IDServer.ActionCancel
        clearText()
        SetCtlEnable(False)
        Me.CheckBox2.Enabled = False
        If SelectNode.Tag.ToString = "All" Then
            bFind = False
        Else
            bFind = True
            FillText(SelectNode.Tag)
        End If
        MainForm.BtnEnable(bFind)
        GetToolEnable()
        ActionHelp = IDServer.IDServer.ActionBtn.ActionHelp
    End Function

    Public Function ActionDelete() As Boolean Implements IDServer.IDServer.IDServer.ActionDelete
        Dim ID As String
        Try
            If DeleteEnable = False Then
                MessageBox.Show(My.Resources.NotAllowDelete, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Function
            End If

            ID = SelectNode.Tag
            If MsgBox(My.Resources.ConfirmDelete, MsgBoxStyle.Information + MsgBoxStyle.OkCancel, Msg.CompanyName) = MsgBoxResult.Ok Then
                If DeleteFromDataSet(ID) = True Then
                    MsgBox(My.Resources.DeleteSuccess, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, Msg.CompanyName)
                End If
            End If
            ActionHelp = IDServer.IDServer.ActionBtn.ActionHelp
            GetToolEnable()
        Catch ex As Exception
            MsgBox("ActionDelete:" + ex.ToString, MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Function

    Public Function ActionEdit() As Boolean Implements IDServer.IDServer.IDServer.ActionEdit
        If EditEnable = False Then
            MessageBox.Show(My.Resources.NotAllowEidt, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Function
        End If
        If Me.TreeView1.SelectedNode Is Nothing Then
            Exit Function
        ElseIf Me.TreeView1.SelectedNode.Tag.ToString.Equals("All", StringComparison.InvariantCultureIgnoreCase) Then
            clearText()
            Exit Function
        End If
        ActionHelp = IDServer.IDServer.ActionBtn.ActionEdit
        MainForm.BtnEnable(False)
        SetCtlEnable(True)
        Me.CheckBox2.Enabled = True
        Me.txtUserName.Focus()
    End Function

    Public Function ActionExport() As Boolean Implements IDServer.IDServer.IDServer.ActionExport

    End Function

    Public Function ActionFilter() As Boolean Implements IDServer.IDServer.IDServer.ActionFilter

    End Function

    Public Function ActionGoFirst() As Boolean Implements IDServer.IDServer.IDServer.ActionGoFirst

    End Function

    Public Function ActionGoLast() As Boolean Implements IDServer.IDServer.IDServer.ActionGoLast

    End Function

    Public Function ActionGoNext() As Boolean Implements IDServer.IDServer.IDServer.ActionGoNext

    End Function

    Public Function ActionGoPrevious() As Boolean Implements IDServer.IDServer.IDServer.ActionGoPrevious

    End Function

    Public Function ActionImport() As Boolean Implements IDServer.IDServer.IDServer.ActionImport

    End Function

    Public Function ActionInitialize() As Boolean Implements IDServer.IDServer.IDServer.ActionInitialize
        Try
            If Me.txtUserName.Text.Length <= 0 Then
                MsgBox(My.Resources.NotNullUserName, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, Msg.CompanyName)
                Me.txtUserName.Focus()
                Return False
            End If
            If Me.txtParssward.Text.Length <= 0 Then
                MsgBox(My.Resources.NotNullUserPassword, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, Msg.CompanyName)
                Me.txtParssward.Focus()
                Return False
            End If
            If Me.txtRePassword.Text.Length <= 0 Then
                MsgBox(My.Resources.NotNullUserRepassword, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, Msg.CompanyName)
                Me.txtRePassword.Focus()
                Return False
            End If
            If Compare(Me.txtParssward.Text, Me.txtRePassword.Text) Then
                MsgBox(My.Resources.NoComparePassword, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, Msg.CompanyName)
                Me.txtParssward.Text = ""
                Me.txtRePassword.Text = ""
                Me.txtParssward.Focus()
                Return False
            End If
            If Me.ComboBox1.SelectedValue.ToString.Length <= 0 Then
                MsgBox("請選擇組別!", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, Msg.CompanyName)
                Me.ComboBox1.Focus()
                SendKeys.Send("{F4}")
                Return False
            End If
            If CDate(Me.txtStartDate.Value) > CDate(Me.txtEndDate.Value) Then
                MsgBox(My.Resources.NotLargeEndDate, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, Msg.CompanyName)
                Me.txtStartDate.Focus()
                SendKeys.Send("{F4}")
                Return False
            End If
            If ActionHelp = IDServer.IDServer.ActionBtn.ActionAdd Then
                Dim sql As String = ""
                Dim m_DS As New DataSet
                sql = "select * from Sys_UserManage where UserCode='" & Me.cmbUserCode.Text & "'"
                m_DS = ReturnDataset(sql)
                If m_DS.Tables(0).Rows.Count > 0 Then
                    MsgBox("此用戶已存在!", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, Msg.CompanyName)
                    Me.ComboBox1.Focus()
                    Return False
                End If
            End If
            Return True
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Public Function ActionPrint() As Boolean Implements IDServer.IDServer.IDServer.ActionPrint

    End Function

    Public Function ActionSave() As Boolean Implements IDServer.IDServer.IDServer.ActionSave
        If BtnActionSave() = True Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function ActionSelect() As Boolean Implements IDServer.IDServer.IDServer.ActionSelect

    End Function

#End Region

#Region "Control Events"

    Private Sub btnSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelect.Click
        If Me.cmbUserCode1.Text.Trim <> "" Then
            Dim node1 As TreeNode

            For Each node As TreeNode In Me.TreeView1.Nodes
                For Each nodec As TreeNode In node.Nodes
                    If nodec.Text.ToLower.Contains("(".ToLower + Me.cmbUserCode1.Text.ToLower.Trim + ")".ToLower) Then
                        node1 = nodec
                    End If
                Next
            Next
            If node1 Is Nothing Then
                Msg.MsgError("找不到用戶：" + Me.cmbUserCode1.Text)
            Else
                Me.TreeView1.Select()
                '先選擇這個（頂層節點），以便控制滾動條
                Me.TreeView1.SelectedNode = Me.TreeView1.TopNode
                Me.TreeView1.SelectedNode = node1
            End If
        End If
    End Sub

    Private Sub cmbUserCode1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cmbUserCode1.KeyDown
        If e.KeyCode = Keys.Enter And Me.cmbUserCode1.Text.Trim <> "" Then
            btnSelect.PerformClick()
        End If
    End Sub

    Private Sub BtnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnOK.Click
        MainForm.ToolStripSave_Click(Nothing, Nothing)
    End Sub

    Private Sub BtnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnCancel.Click
        MainForm.ToolStripCancel_Click(Nothing, Nothing)
    End Sub

    Private Sub TreeView1_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
        Try
            SelectNode = e.Node
            If e.Action = TreeViewAction.ByKeyboard Or e.Node.Tag.ToString = "All" Then
                clearText()
            Else
                FillText(SelectNode.Tag)
                bFind = True
                MainForm.BtnEnable(bFind)
                GetToolEnable()
            End If
        Catch ex As Exception
            MsgBox("TreeView1_AfterSelect:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    Private Sub txtUserName_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtUserName.KeyDown, cmbUserCode.KeyDown, txtParssward.KeyDown, txtRePassword.KeyDown, txtStartDate.KeyDown, txtEndDate.KeyDown, CheckBox1.KeyDown, ComboBox1.KeyDown
        Try
            If e.KeyCode = Keys.Shift Then
                e.Handled = True
                If e.KeyCode = Keys.Enter Then
                    SendKeys.Send("+{TAB}")
                    SendKeys.Send("{F4}")
                End If
            Else
                Select Case e.KeyCode
                    Case Keys.Enter
                        e.Handled = True
                        SendKeys.Send("{TAB}")
                        SendKeys.Send("{F4}")
                End Select
            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub cmbUserCode_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbUserCode.SelectedIndexChanged

        Me.txtUserName.Text = Me.cmbUserCode.SelectedValue.ToString
    End Sub

    Private Sub CheckBox2_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged

        If ActionHelp = IDServer.IDServer.ActionBtn.ActionEdit Then
            Me.txtParssward.Enabled = Me.CheckBox2.Checked
            Me.txtRePassword.Enabled = Me.CheckBox2.Checked
        End If

    End Sub

#End Region

End Class
